﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Data;
using System.Collections;
using MySimpleWCFService.interfaсes;

namespace MySimpleWCFService
{
    /// <summary>
    /// Works with Jabber Extensions
    /// Author: alexandr.pec@skypro.ch
    /// </summary>
    public class Jabber : IJabber
    {

        System.Diagnostics.EventLog _appLog = null;
        System.Diagnostics.EventLog appLog
        {
            get
            {
                if (_appLog == null)
                    _appLog = new System.Diagnostics.EventLog();
                _appLog.Source = "MySimpleWCFService";
                return _appLog;
            }
        }


        /// <summary>
        /// Create Jabber Account
        /// </summary>
        /// <param name="paramLogin"></param>
        /// <param name="paramPassword"></param>
        /// <returns></returns>
        public bool AddJabberAccount(string paramLogin, string paramPassword)
        {
            string locRes = string.Empty;
            bool locResStatus = false;

            appLog.WriteEntry("AddJabber"+
                ": paramLogin:'" + paramLogin +
                "', paramPassword:'" + paramPassword);

            try
            {
                locRes = VoipNowSOAP.JabberWorks.AddJabberAccount(
                    paramLogin, paramPassword);
                locResStatus = true;
            }
            catch (Exception exc)
            {
                locResStatus = false;
                appLog.WriteEntry("AddJabber: Exception:'" + exc.Message + "'");
                if( exc.InnerException != null)
                    appLog.WriteEntry("AddJabber: InnerException:'" + exc.InnerException.Message + "'");
                throw exc;
            }
            appLog.WriteEntry("AddJabber: OK:'" + locRes + "'");
            return locResStatus;
        }
    }
}
